Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class codingQuestion3 {
- public static void concat1(String s1) { s1 = s1 + "test1"; }
- public static void concat2(StringBuilder s2) { s2.append("test2"); }
- public static void concat3(StringBuffer s3) { s3.append("test3"); }
- public static void main(String[] args) {
- String s1 = "test1"; concat1(s1); test1test1 System.out.println("String: " + s1); StringBuilder s2 = new StringBuilder("test2"); concat2(s2); test2test2 System.out.println("StringBuilder: " + s2); StringBuffer s3 = new StringBuffer("test3"); concat3(s3); System.out.println("StringBuffer: " + s3); } }
- abstract class Bank { abstract int getRateOfInterest(); }
- class SBI extends Bank { int getRateOfInterest() { return 7; }
- void test() { System.out.println("test called"); } }
- class PNB extends Bank { int getRateOfInterest() { return 8; } }
- class TestBank { public static void main(String args[]) { Bank b = new SBI(); b.test(); SBI k = new SBI(); k.test(); test called int interest = b.getRateOfInterest(); System.out.println("Rate of Interest is: " + interest + " %"); } }
- class P { static void ab() { System.out.println("P"); } }
- class A extends P { static void ab() { System.out.println("a"); } }
- class B extends P { static void ab() { System.out.println("b"); }
- public static void main(String ar[]) { P p = new A(); A a = new A(); p.ab(); p = new B(); p.ab(); a.ab(); }
- 10
- 6 4
- 3 3 2 2
- Public boolean isSumTree(TreeNode root)
- {
- return helper(root);
- }
- Public boolean helper(TreeNode root)
- {
- if(root == null)
- return true;
- if(root.left == null && root.right == null)
- return true;
- int sum = root.left == null?0:root.left.data + root.right == null?0:root.data;
- if(sum != root.data)
- return false;
- return helper(root.left) && helper(root.right);
- }
Advertisement
Add Comment
Please, Sign In to add comment